﻿#include <QMessageBox>
#include <QTime>
#include <QSettings>
#include <QTimer>
#include "CSamReg.h"
#include "OraclDbThread.h"
#include "AccessDbThread.h"
#include "controldelegate.h"
#include "CManualSampleSys.h"


CSamReg::CSamReg(QWidget *parent)
	: QWidget(parent)
{
	ui.setupUi(this);
	m_pSamRegistrationModel = NULL;
	m_pParent = NULL;
	this->setWindowTitle(A2T("样品登记"));
	this->setWindowFlags(windowFlags()&~Qt::WindowContextHelpButtonHint);
	this->setAttribute(Qt::WA_ShowModal, true);
	PreInit();

	connect(ui.RegistrationOKBtn, SIGNAL(clicked()), this, SLOT(RegistrationOK()));
	connect(ui.SamSubmissionBtn, SIGNAL(clicked()), this, SLOT(SamSubmission()));
	connect(ui.RecordDeleteBtn, SIGNAL(clicked()), this, SLOT(RecordDelete()));
	connect(ui.ReadSampleCodeBtn, SIGNAL(clicked()), this, SLOT(slot_ReadSampleCode()));
	connect(ui.pushButtonGetWeight, SIGNAL(clicked()), this, SLOT(slot_GetWeightCode()));
	connect(ui.pushButtonPrintSampleCode, SIGNAL(clicked()), this, SLOT(slot_PrintSampleCode()));
	connect(ui.pushButtonUpdateToTableView, SIGNAL(clicked()), this, SLOT(on_AddAccessToTableView()));

	connect(ui.radioButton, SIGNAL(toggled(bool)), this, SLOT(on_RadioButton(bool)));
}

CSamReg::~CSamReg()
{
	if (nullptr != m_pSamRegistrationModel)
	{
		SAFE_DELETE(m_pSamRegistrationModel);
	}
	m_pParent->m_pSamReg = NULL;
}

void CSamReg::PreInit()
{
	//初始化样品登记tableView
	//设置表头可点击
	ui.widget->ui.tableView->horizontalHeader()->setSectionsClickable(true);
	//设置表头字体
	ui.widget->ui.tableView->horizontalHeader()->setFont(QFont("Microsoft YaHei UI", 15));
	if (!ui.widget->ui.tableView->alternatingRowColors())
	{
		ui.widget->ui.tableView->setAlternatingRowColors(true);
	}
	ui.widget->ui.tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
	ui.widget->ui.tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
	ui.widget->ui.tableView->setSelectionMode(QAbstractItemView::SingleSelection);
	ui.widget->ui.tableView->horizontalHeader()->setStretchLastSection(true);
	m_pSamRegistrationModel = new QStandardItemModel();
	m_pSamRegistrationModel->setColumnCount(5);
	m_pSamRegistrationModel->setHeaderData(0, Qt::Horizontal, "选择");//设置表头
	m_pSamRegistrationModel->setHeaderData(1, Qt::Horizontal, "采样编码");//设置表头
	m_pSamRegistrationModel->setHeaderData(2, Qt::Horizontal, "重量(KG)");
	m_pSamRegistrationModel->setHeaderData(3, Qt::Horizontal, "登记时间");
	m_pSamRegistrationModel->setHeaderData(4, Qt::Horizontal, "备注");
	ui.widget->ui.tableView->setModel(m_pSamRegistrationModel);

	ui.widget->ui.tableView->setColumnWidth(0, 50);//设置列宽
	ui.widget->ui.tableView->setColumnWidth(1, 200);//设置列宽
	ui.widget->ui.tableView->setColumnWidth(2, 200);
	ui.widget->ui.tableView->setColumnWidth(3, 400);
	ui.widget->ui.tableView->setColumnWidth(4, 800);
	ui.widget->ui.tableView->setSelectionBehavior(QAbstractItemView::SelectRows);//设置选中时为选中整行
	ui.widget->ui.tableView->setEditTriggers(QAbstractItemView::DoubleClicked);
	ReadOnlyDelegate* readOnlyDelegate = new ReadOnlyDelegate(this);//使用委托设置tableview的1、3列不可编辑
	ui.widget->ui.tableView->setItemDelegateForColumn(1, readOnlyDelegate);
	ui.widget->ui.tableView->setItemDelegateForColumn(2, readOnlyDelegate);
	ui.widget->ui.tableView->setItemDelegateForColumn(3, readOnlyDelegate);

	connect(m_pSamRegistrationModel, SIGNAL(dataChanged(QModelIndex, QModelIndex, QVector<int>)), this, SLOT(on_CurrentChanged(QModelIndex, QModelIndex, QVector<int>)));
	//初始化全选复选框
	ui.checkBox->setCheckState(Qt::CheckState::PartiallyChecked);
	ui.checkBox->setCheckState(Qt::CheckState::Unchecked);  //设置全选初始
	connect(ui.checkBox, SIGNAL(stateChanged(int)), this, SLOT(slot_checkAll(int)));
	if (g_nProjectNo == 1)//兆光
	{
		ui.pushButtonGetWeight->hide();
		ui.radioButton->hide();
		ui.ReadSampleCodeBtn->hide();
		ui.pushButtonPrintSampleCode->hide();
	}
	else if (g_nProjectNo == 4)//科右中默认为25KG
	{
		ui.lineEditWeight->setText("25");
	}

	if (g_nProjectNo == 6)//6:河津
	{
		ui.pushButtonPrintSampleCode->hide();//打印采样码隐藏
		ui.pushButtonGetWeight->hide();//获取重量隐藏
		//默认重量0 然后隐藏掉
		ui.lineEditWeight->setText("0");
		ui.labelWeight->hide();
		ui.lineEditWeight->hide();

		//隐藏表格重量列 index2
		ui.widget->hideOneCol(2);

	}

	if (g_nProjectNo == 7)//7:新疆天河
	{
		ui.pushButtonPrintSampleCode->hide();//打印采样码隐藏
		ui.pushButtonGetWeight->hide();//获取重量隐藏

		//默认重量0 然后隐藏掉
		ui.lineEditWeight->setText("0");
		ui.labelWeight->hide();
		ui.lineEditWeight->hide();

		//隐藏表格重量列 index2
		ui.widget->hideOneCol(2);

		//隐藏读采样编码按钮
		ui.ReadSampleCodeBtn->hide();

		//隐藏是否默认选框
		ui.radioButton->hide();
	}
}

void CSamReg::InsertAccessSamReg(QString strCurrentDateTime, QString strSampleCode, QString strWeight, int& nFlag)
{
	//将新增的记录插入到本地Access数据库中
	{
		//首先检查本地数据库中是否有这个采样编码的记录
		DbOperContent sDbOpeContent(enumSqlType::enSamReg);
		if (NULL == sDbOpeContent.pSampleRegTable)
		{
			ADDMSG("数据库模块", enEventAlarm, FL, _Q(QString("样品登记表指针创建失败")));
			return;
		}
		sDbOpeContent.pSampleRegTable->nOpType = 7; //插入数据
		strcpy(sDbOpeContent.pSampleRegTable->strSampleCode, strSampleCode.toLatin1().data());
		QString strErrMsg = "";
		QDStrs dsFields;
		if (false == g_pLocalDbThread->AddDbOperTask(&sDbOpeContent, &dsFields, strErrMsg))
		{
			ADDMSG("数据库模块", enEventAlarm, FL, _Q(strErrMsg));
			return;
		}
		if (dsFields.size() == 0)//说明这个记录是第一次添加,再次登记的时候不需要在数据库中进行添加
		{
			nFlag = 1;
			//添加记录
			DbOperContent sDbOpeContent(enumSqlType::enSamReg);
			if (NULL == sDbOpeContent.pSampleRegTable)
			{
				ADDMSG("数据库模块", enEventAlarm, FL, _Q(QString("样品登记表指针创建失败")));
				return;
			}
			sDbOpeContent.pSampleRegTable->nOpType = 0; //插入数据，并把是否提交设为0
			strcpy(sDbOpeContent.pSampleRegTable->strInsertTime, strCurrentDateTime.toLatin1().data());
			strcpy(sDbOpeContent.pSampleRegTable->strSampleCode, strSampleCode.toLatin1().data());
			strcpy(sDbOpeContent.pSampleRegTable->strSampleWeight, strWeight.toLatin1().data());
			QString strErrMsg = "";
			QDStrs dsFields;
			if (false == g_pLocalDbThread->AddDbOperTask(&sDbOpeContent, &dsFields, strErrMsg))
			{
				ADDMSG("数据库模块", enEventAlarm, FL, _Q(strErrMsg));
				return;
			}
		}
	}

}

bool CSamReg::QueryThreeLevelCodeTable(QString SampleCode, int nTime)
{
	//QDateTime time = QDateTime::currentDateTime().addSecs(nTime * 600);
	QDateTime time = QDateTime::currentDateTime();
	QString strCurrentDateTime = time.toString("yyyy/MM/dd hh:mm:ss");
	//在Oracle数据库三级编码表中查找对应的制样编码
	DbOperContent sDbOpeContent(enumSqlType::enenThreeLevelCode);
	if (NULL == sDbOpeContent.pThreeLevelCodeTable)
	{
		ADDMSG("数据库模块", enEventAlarm, FL, _Q(QString("三级编码表指针创建失败")));
		return false;
	}
	sDbOpeContent.pThreeLevelCodeTable->nOpType = 0; //根据采样码查出制样码
	strcpy(sDbOpeContent.pThreeLevelCodeTable->szSampleCode, SampleCode.toLatin1().data());
	QString strErrMsg = "";
	QDStrs dsFields;

	if (g_nOracleorAccess==0)
	{
		if (false == g_pDbThread->AddDbOperTask(&sDbOpeContent, &dsFields, strErrMsg))
		{
			ADDMSG("数据库模块", enEventAlarm, FL, _Q(strErrMsg));
			return false;
		}
	}
	else 
	{
		if (false == g_pLocalDbThread->AddDbOperTask(&sDbOpeContent, &dsFields, strErrMsg))
		{
			ADDMSG("数据库模块", enEventAlarm, FL, _Q(strErrMsg));
			return false;
		}
		
	}
	//开始解析三级编码表数据
	//QString strSampleCode;//采样码
	QString strProviderNo;//供应商编号
	QString strBatchNo; //采样批次
	QString strInserDate; //插入记录时间
	QString strMakeSampleCode; //制样码
	QString strExamineSampleCode;//化样码
	QString strCoalType; //煤种类型
	QString strCodeType;//编码类型
	QString DevNo; //机组编号

	if (dsFields.size() == 1)  //查询的结构是一条记录,证明当前的样品还没有制样或者制过一次
	{
		QVector<QString> vecTHREELEVELCODEINFO = dsFields.at(0);
		if (vecTHREELEVELCODEINFO.size() < 17)
		{
			ADDMSG("数据库模块", enEventAlarm, FL, _Q(QString("三级编码表中的列数过少，第%d行数据无效")));
		}
		strMakeSampleCode = vecTHREELEVELCODEINFO.at(4);
		strProviderNo = vecTHREELEVELCODEINFO.at(0);
		strBatchNo = vecTHREELEVELCODEINFO.at(1);
		strInserDate = vecTHREELEVELCODEINFO.at(2);
		strCoalType = vecTHREELEVELCODEINFO.at(6);
		strCodeType = vecTHREELEVELCODEINFO.at(7);
		DevNo = vecTHREELEVELCODEINFO.at(16);
		if (strMakeSampleCode == "")//没有关联到制样编码
		{
			QMessageBox::critical(NULL, "error", "没有关联出制样码，请检查采样编码是否正确", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
			return false;
		}
		//查询当前的采样编码在制样记录表中的记录数
		int nCount = QueryMsReCodeTable(strMakeSampleCode);
		//开始解析制样记录表中的数据
		if (nCount == 0)//没有制样记录，则用当前的编码进行人工制样，最后将记录插入到本地的制样记录表中
		{
			//全局的数组中增加一条
			MakeSamRegItem* item = new MakeSamRegItem();
			item->isChecked = false;
			strcpy(item->strMsDeviceID, "260003");
			strcpy(item->strProviderNo, strProviderNo.toLatin1().data());
			strcpy(item->strMakeSampleCode, strMakeSampleCode.toLatin1().data());
			strcpy(item->strSTARTTIME, strCurrentDateTime.toLatin1().data());
			strcpy(item->strEDITMODE, "1");
			strcpy(item->strSampleWeight, QString::number(g_mapSamReg[SampleCode]).toLatin1().data());
			g_vecMakeSamRegItem.push_back(item);
			//直接将这个采样码对应的样品加入到制样登记界面的tableview中
			addRecordToMakeSamReg(SampleCode, strMakeSampleCode, strProviderNo, strCurrentDateTime);
			addMakeSamRecordToAccess(SampleCode, strProviderNo, strMakeSampleCode, strCurrentDateTime);//本地数据库制样记录表插入记录
		}
		else  //需要分批制样
		{
			int ret = QMessageBox::information(NULL, "", QString("采样码为%1的样品需要进行分批制样，请确认是否继续").arg(SampleCode), QMessageBox::Yes, QMessageBox::No);
			if (ret == QMessageBox::No)
			{
				return false;
			}
			//生成新的制样码和化验码，并在本地Access制样记录表，Oracle端三级编码表、制样记录表中加入新的记录
			QString strNewMakeSampleCode;//新的制样码
			QString strNewExamineSmapleCode;//新的化验码
			if (!MakeThreeLevelCode(SampleCode, strNewMakeSampleCode, strNewExamineSmapleCode))
			{
				return false;
			}
			//将新的三级编码插入到Oracle数据库中
			DbOperContent sDbOpeContent(enumSqlType::enenThreeLevelCode);
			if (NULL == sDbOpeContent.pThreeLevelCodeTable)
			{
				ADDMSG("数据库模块", enEventAlarm, FL, _Q(QString("制样记录表指针创建失败")));
				return false;
			}
			sDbOpeContent.pThreeLevelCodeTable->nOpType = 2; //三级编码表中增加记录
			strcpy(sDbOpeContent.pThreeLevelCodeTable->szSampleCode, SampleCode.toLatin1().data());
			strcpy(sDbOpeContent.pThreeLevelCodeTable->szMakeSampleCode, strNewMakeSampleCode.toLatin1().data());
			strcpy(sDbOpeContent.pThreeLevelCodeTable->szExamineSampleCode, strNewExamineSmapleCode.toLatin1().data());
			strcpy(sDbOpeContent.pThreeLevelCodeTable->szBatchNo, strBatchNo.toLatin1().data());
			strcpy(sDbOpeContent.pThreeLevelCodeTable->szProviderNo, strProviderNo.toLatin1().data());
			strcpy(sDbOpeContent.pThreeLevelCodeTable->szInsertDate, strInserDate.toLatin1().data());
			strcpy(sDbOpeContent.pThreeLevelCodeTable->szCoalType, strCoalType.toLatin1().data());
			strcpy(sDbOpeContent.pThreeLevelCodeTable->szCodeType, strCodeType.toLatin1().data());
			strcpy(sDbOpeContent.pThreeLevelCodeTable->szDevNo, DevNo.toLatin1().data());
			QString strErrMsg = "";
			QDStrs dsFields;
			if (g_nOracleorAccess == 0)
			{
				if (false == g_pDbThread->AddDbOperTask(&sDbOpeContent, &dsFields, strErrMsg))
				{
					ADDMSG("数据库模块", enEventAlarm, FL, _Q(strErrMsg));
					return false;
				}
			}
			else
			{
				if (false == g_pLocalDbThread->AddDbOperTask(&sDbOpeContent, &dsFields, strErrMsg))
				{
					ADDMSG("数据库模块", enEventAlarm, FL, _Q(strErrMsg));
					return false;
				}

			}
			//全局的数组中增加一条
			MakeSamRegItem* item = new MakeSamRegItem();
			item->isChecked = false;
			strcpy(item->strMsDeviceID, "260003");
			strcpy(item->strProviderNo, strProviderNo.toLatin1().data());
			strcpy(item->strMakeSampleCode, strNewMakeSampleCode.toLatin1().data());
			strcpy(item->strSTARTTIME, strCurrentDateTime.toLatin1().data());
			strcpy(item->strEDITMODE, "1");
			strcpy(item->strSampleWeight, QString::number(g_mapSamReg[SampleCode]).toLatin1().data());
			g_vecMakeSamRegItem.push_back(item);
			addRecordToMakeSamReg(SampleCode, strNewMakeSampleCode, strProviderNo, strCurrentDateTime);
			addMakeSamRecordToAccess(SampleCode, strProviderNo, strNewMakeSampleCode, strCurrentDateTime);//本地数据库制样记录表插入记录
		}
	}
	else if (dsFields.size() > 1)//查询到的记录条数大于1  直接证明需要分批制样
	{
		int ret = QMessageBox::information(NULL, "", QString("采样码为%1的样品需要进行分批制样，请确认是否继续").arg(SampleCode), QMessageBox::Yes, QMessageBox::No);
		if (ret == QMessageBox::No)
		{
			return false;
		}
		QVector<QString> vecTHREELEVELCODEINFO = dsFields.at(0);
		if (vecTHREELEVELCODEINFO.size() < 17)
		{
			ADDMSG("数据库模块", enEventAlarm, FL, _Q(QString("三级编码表中的列数过少，第%d行数据无效")));
		}
		strMakeSampleCode = vecTHREELEVELCODEINFO.at(4);
		strProviderNo = vecTHREELEVELCODEINFO.at(0);
		strBatchNo = vecTHREELEVELCODEINFO.at(1);
		strInserDate = vecTHREELEVELCODEINFO.at(2);
		strCoalType = vecTHREELEVELCODEINFO.at(6);
		strCodeType = vecTHREELEVELCODEINFO.at(7);
		DevNo = vecTHREELEVELCODEINFO.at(16);
		if (strMakeSampleCode == "")//没有关联到制样编码
		{
			QMessageBox::critical(NULL, "error", "没有关联出制样码，请检查采样编码是否正确", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
			return false;
		}
		//生成新的制样码和化验码，并在本地Access制样记录表，Oracle端三级编码表、制样记录表中加入新的记录
		QString strNewMakeSampleCode;//新的制样码
		QString strNewExamineSmapleCode;//新的化验码
		if (!MakeThreeLevelCode(SampleCode, strNewMakeSampleCode, strNewExamineSmapleCode))
		{
			return false;
		}
		//将新的三级编码插入到Oracle数据库中
		DbOperContent sDbOpeContent(enumSqlType::enenThreeLevelCode);
		if (NULL == sDbOpeContent.pThreeLevelCodeTable)
		{
			ADDMSG("数据库模块", enEventAlarm, FL, _Q(QString("制样记录表指针创建失败")));
			return false;
		}
		sDbOpeContent.pThreeLevelCodeTable->nOpType = 2; //三级编码表中增加记录
		strcpy(sDbOpeContent.pThreeLevelCodeTable->szSampleCode, SampleCode.toLatin1().data());
		strcpy(sDbOpeContent.pThreeLevelCodeTable->szMakeSampleCode, strNewMakeSampleCode.toLatin1().data());
		strcpy(sDbOpeContent.pThreeLevelCodeTable->szExamineSampleCode, strNewExamineSmapleCode.toLatin1().data());
		strcpy(sDbOpeContent.pThreeLevelCodeTable->szBatchNo, strBatchNo.toLatin1().data());
		strcpy(sDbOpeContent.pThreeLevelCodeTable->szProviderNo, strProviderNo.toLatin1().data());
		strcpy(sDbOpeContent.pThreeLevelCodeTable->szInsertDate, strInserDate.toLatin1().data());
		strcpy(sDbOpeContent.pThreeLevelCodeTable->szCoalType, strCoalType.toLatin1().data());
		strcpy(sDbOpeContent.pThreeLevelCodeTable->szCodeType, strCodeType.toLatin1().data());
		strcpy(sDbOpeContent.pThreeLevelCodeTable->szDevNo, DevNo.toLatin1().data());
		QString strErrMsg = "";
		QDStrs dsFields;
		if (g_nOracleorAccess == 0)
		{
			if (false == g_pDbThread->AddDbOperTask(&sDbOpeContent, &dsFields, strErrMsg))
			{
				ADDMSG("数据库模块", enEventAlarm, FL, _Q(strErrMsg));
				return false;
			}
		}
		else
		{
			if (false == g_pLocalDbThread->AddDbOperTask(&sDbOpeContent, &dsFields, strErrMsg))
			{
				ADDMSG("数据库模块", enEventAlarm, FL, _Q(strErrMsg));
				return false;
			}

		}
		//全局的数组中增加一条
		MakeSamRegItem* item = new MakeSamRegItem();
		item->isChecked = false;
		strcpy(item->strMsDeviceID, "260003");
		strcpy(item->strProviderNo, strProviderNo.toLatin1().data());
		strcpy(item->strMakeSampleCode, strNewMakeSampleCode.toLatin1().data());
		strcpy(item->strSTARTTIME, strCurrentDateTime.toLatin1().data());
		strcpy(item->strEDITMODE, "1");
		strcpy(item->strSampleWeight, QString::number(g_mapSamReg[SampleCode]).toLatin1().data());
		g_vecMakeSamRegItem.push_back(item);
		addRecordToMakeSamReg(SampleCode, strNewMakeSampleCode, strProviderNo, strCurrentDateTime);
		addMakeSamRecordToAccess(SampleCode, strProviderNo, strNewMakeSampleCode, strCurrentDateTime);//本地数据库制样记录表插入记录
	}
	return true;
}

int CSamReg::QueryMsReCodeTable(QString strMakeSampleCode)
{
	//根据制样码，到Oracle数据库中的制样记录表中查询是否有这个样的制样记录
	//若有：则提醒分批制样并生成新的制样、化样编码
	//若没有：则用当前的制样编码进行人工制样，最后将记录插入到本地的制样记录表中
	//在Oracle数据库三级编码表中查找对应的制样编码
	DbOperContent sDbOpeContent(enumSqlType::enMsReCode);
	if (NULL == sDbOpeContent.pMsReCodeTable)
	{
		ADDMSG("数据库模块", enEventAlarm, FL, _Q(QString("制样记录表指针创建失败")));
		return 0;
	}
	sDbOpeContent.pMsReCodeTable->nOpType = 0; //根据制样码查询是否有制样记录
	strcpy(sDbOpeContent.pMsReCodeTable->strMakeSampleCode, strMakeSampleCode.toLatin1().data());
	QString strErrMsg = "";
	QDStrs dsFields;
	if (g_nOracleorAccess == 0)
	{
		if (false == g_pDbThread->AddDbOperTask(&sDbOpeContent, &dsFields, strErrMsg))
		{
			ADDMSG("数据库模块", enEventAlarm, FL, _Q(strErrMsg));
			return false;
		}
	}
	else
	{
		if (false == g_pLocalDbThread->AddDbOperTask(&sDbOpeContent, &dsFields, strErrMsg))
		{
			ADDMSG("数据库模块", enEventAlarm, FL, _Q(strErrMsg));
			return false;
		}

	}
	return dsFields.size();
}

void CSamReg::addRecordToMakeSamReg(QString strSampleCode, QString strMakeSampleCode, QString strProviderNo, QString strStartTime)
{
	if (g_nProjectNo == 1)
	{
		if (this->m_pParent->m_pmakeSamRegZG == nullptr)
		{
			m_pParent->slotPushButtonZYDJZGClicked();
		}
		int nRowCount = m_pParent->m_pmakeSamRegZG->m_pMakeSamRegModel->rowCount();
		QList<QStandardItem*> item;
		item.append(new QStandardItem());//选择
		item.append(new QStandardItem(QString::number(m_pParent->m_pmakeSamRegZG->m_nCount++)));//序号
		item.append(new QStandardItem("260003"));//制样机编号
		item.append(new QStandardItem(strProviderNo));//供应商编号
		item.append(new QStandardItem(strSampleCode));//采样编码
		item.append(new QStandardItem(strMakeSampleCode));//制样编码
		item.append(new QStandardItem());//3mm瓶底码
		item.append(new QStandardItem());//6mm1瓶底码
		item.append(new QStandardItem());//6mm2瓶底码
		item.append(new QStandardItem());//0.2mm存查样瓶底码
		item.append(new QStandardItem());//0.2mm分析样瓶底码
		item.append(new QStandardItem());//3mm重量
		item.append(new QStandardItem());//6mm1重量
		item.append(new QStandardItem());//6mm2重量
		item.append(new QStandardItem());//0.2mm存查样重量码
		item.append(new QStandardItem());//0.2mm分析样重量码
		item.append(new QStandardItem(strStartTime));//制样开始时间
		item.append(new QStandardItem());//制样结束时间
		item.append(new QStandardItem("人工制样"));//编辑模式
		item.append(new QStandardItem(g_strOperName));//操作员姓名
		item.append(new QStandardItem(QString::number(g_mapSamReg[strSampleCode])));//样品总重量
		m_pParent->m_pmakeSamRegZG->m_pMakeSamRegModel->insertRow(m_pParent->m_pmakeSamRegZG->m_pMakeSamRegModel->rowCount(), item);
		//设置居中显示
		for (int nRow = 0; nRow < item.count(); nRow++)
		{
			item.at(nRow)->setTextAlignment(Qt::AlignCenter);
		}

		//添加复选框
		QWidget *pwidget = new QWidget;
		QHBoxLayout *hlayout = new QHBoxLayout;
		hlayout->setAlignment(Qt::AlignLeft);
		QCheckBox *chebox = new QCheckBox;
		chebox->setObjectName("singleCheck");
		hlayout->addWidget(chebox);
		pwidget->setLayout(hlayout);
		connect(chebox, SIGNAL(clicked()), m_pParent->m_pmakeSamRegZG, SLOT(slot_tCheckItem()));
		m_pParent->m_pmakeSamRegZG->ui.widget->ui.tableView->setIndexWidget(m_pParent->m_pmakeSamRegZG->m_pMakeSamRegModel->index(nRowCount, 0), pwidget);
	}
	else
	{
		if (this->m_pParent->m_pmakeSamReg == nullptr)
		{
			m_pParent->slotPushButtonZYDJClicked();
		}
		int nRowCount = m_pParent->m_pmakeSamReg->m_pMakeSamRegModel->rowCount();
		QList<QStandardItem*> item;
		item.append(new QStandardItem());//选择
		item.append(new QStandardItem(QString::number(m_pParent->m_pmakeSamReg->m_nCount++)));//序号
		item.append(new QStandardItem("260003"));//制样机编号
		item.append(new QStandardItem(strProviderNo));//供应商编号
		item.append(new QStandardItem(strSampleCode));//采样编码
		item.append(new QStandardItem(strMakeSampleCode));//制样编码
		item.append(new QStandardItem());//3mm瓶底码
		item.append(new QStandardItem());//6mm1瓶底码
		item.append(new QStandardItem());//6mm2瓶底码
		item.append(new QStandardItem());//0.2mm分析样瓶底码
		item.append(new QStandardItem());//0.2mm存查样瓶底码
		item.append(new QStandardItem());//3mm重量
		item.append(new QStandardItem());//6mm1重量
		item.append(new QStandardItem());//6mm1重量
		item.append(new QStandardItem());//0.2mm分析样重量
		item.append(new QStandardItem());//0.2mm存查样重量
		item.append(new QStandardItem(strStartTime));//制样开始时间
		item.append(new QStandardItem());//制样结束时间
		item.append(new QStandardItem("人工制样"));//编辑模式
		item.append(new QStandardItem(g_strOperName));//操作员姓名
		item.append(new QStandardItem(QString::number(g_mapSamReg[strSampleCode])));//样品总重量

		m_pParent->m_pmakeSamReg->m_pMakeSamRegModel->insertRow(m_pParent->m_pmakeSamReg->m_pMakeSamRegModel->rowCount(), item);
		//设置居中显示
		for (int nRow = 0; nRow < item.count(); nRow++)
		{
			item.at(nRow)->setTextAlignment(Qt::AlignCenter);
		}

		//添加复选框
		QWidget *pwidget = new QWidget;
		QHBoxLayout *hlayout = new QHBoxLayout;
		hlayout->setAlignment(Qt::AlignLeft);
		QCheckBox *chebox = new QCheckBox;
		chebox->setObjectName("singleCheck");
		hlayout->addWidget(chebox);
		pwidget->setLayout(hlayout);
		connect(chebox, SIGNAL(clicked()), m_pParent->m_pmakeSamReg, SLOT(slot_tCheckItem()));
		m_pParent->m_pmakeSamReg->ui.widget->ui.tableView->setIndexWidget(m_pParent->m_pmakeSamReg->m_pMakeSamRegModel->index(nRowCount, 0), pwidget);
	}
}

bool CSamReg::MakeThreeLevelCode(QString strSampleCode, QString& strNewMakeSampleCode, QString& strNewExamineSmapleCode)
{
	bool bCreateSuccess = false;
	int nCount = 0;
	//制样编码
	QString strMakeSampleCode = "";

	//化验编码
	QString strExamineSampleCode = "";

	//采样码前缀 也就是该采样码的：年月日
	QString strPrefix = strSampleCode.left(8);

	while (nCount++ < 1000)
	{
		QTime time;
		time = QTime::currentTime();
		qsrand(time.msec() + time.second() * 1000);
		int n1 = qrand() % 1000;
		int n2 = qrand() % 1000;
		//制样编码
		strMakeSampleCode.sprintf("%s%03d", strPrefix.toLatin1().data(), n1);

		//化验编码
		strExamineSampleCode.sprintf("%s%03d", strPrefix.toLatin1().data(), n2);

		//编码两两不能相同
		if (strSampleCode == strMakeSampleCode || strSampleCode == strExamineSampleCode || strMakeSampleCode == strExamineSampleCode)
		{
			continue;
		}
		{
			//查询是否存在相同的采制化编码
			char szErrMsg[128] = { 0 };
			DbOperContent sDbOpeContent(enumSqlType::enenThreeLevelCode);
			sDbOpeContent.pThreeLevelCodeTable->nOpType = 1;//1：根据制、化两个编码进行查找
			sprintf(sDbOpeContent.pThreeLevelCodeTable->szMakeSampleCode, strMakeSampleCode.toLatin1().data());
			sprintf(sDbOpeContent.pThreeLevelCodeTable->szExamineSampleCode, strExamineSampleCode.toLatin1().data());

			QString strErrMsg = "";
			QDStrs dsFields;
			g_pLocalDbThread->AddDbOperTask(&sDbOpeContent, &dsFields, strErrMsg);
			if (dsFields.size() > 0)
			{
				continue;
			}
			else
			{
				ADDMSG("系统", enEventInfo, FL, _Q(QString("生成新的制样码、化验码成功,采样码为'%1',制样码为'%2',化验码为'%3'").arg(strSampleCode).arg(strMakeSampleCode).arg(strExamineSampleCode)));
				bCreateSuccess = true;
				strNewMakeSampleCode = strMakeSampleCode;
				strNewExamineSmapleCode = strExamineSampleCode;
				break;
			}
		}
		{
			char szErrMsg[128] = { 0 };
			DbOperContent sDbOpeContent(enumSqlType::enenThreeLevelCode);
			sDbOpeContent.pThreeLevelCodeTable->nOpType = 2;//1：根据制、化两个编码进行查找
			sprintf(sDbOpeContent.pThreeLevelCodeTable->szMakeSampleCode, strMakeSampleCode.toLatin1().data());
			sprintf(sDbOpeContent.pThreeLevelCodeTable->szExamineSampleCode, strExamineSampleCode.toLatin1().data());

			QString strErrMsg = "";
			QDStrs dsFields;
			if (g_pLocalDbThread->AddDbOperTask(&sDbOpeContent, &dsFields, strErrMsg))
			{
				ADDMSG("系统", enEventInfo, FL, _Q(QString("生成新的制样码、化验码成功,采样码为'%1',制样码为'%2',化验码为'%3'").arg(strSampleCode).arg(strMakeSampleCode).arg(strExamineSampleCode)));
				bCreateSuccess = true;
				strNewMakeSampleCode = strMakeSampleCode;
				strNewExamineSmapleCode = strExamineSampleCode;
				break;
			}
		}
	}

	if (false == bCreateSuccess)
	{
		ADDMSG("系统", enEventInfo, FL, _Q(QString("生成新的制样码、化验码失败")));
		return false;
	}
	else
	{
		return true;
	}
}

void CSamReg::addMakeSamRecordToAccess(QString strSampleCode, QString strProviderNo, QString strMakeSampleCode, QString strStartTime)
{
	DbOperContent sDbOpeContent(enumSqlType::enMsReCode);
	if (NULL == sDbOpeContent.pMsReCodeTable)
	{
		ADDMSG("数据库模块", enEventAlarm, FL, _Q(QString("制样记录表指针创建失败")));
		return;
	}
	sDbOpeContent.pMsReCodeTable->nOpType = 1; //插入数据

	strcpy(sDbOpeContent.pMsReCodeTable->strProviderNo, strProviderNo.toLatin1().data());
	strcpy(sDbOpeContent.pMsReCodeTable->strMakeSampleCode, strMakeSampleCode.toLatin1().data());
	strcpy(sDbOpeContent.pMsReCodeTable->strSTARTTIME, strStartTime.toLatin1().data());
	strcpy(sDbOpeContent.pMsReCodeTable->strMsDeviceID, "260003");
	strcpy(sDbOpeContent.pMsReCodeTable->strEDITMODE, "0");
	strcpy(sDbOpeContent.pMsReCodeTable->strOPERATERNAME, g_strOperName.toLocal8Bit().data());
	strcpy(sDbOpeContent.pMsReCodeTable->strSampleWeight, QString::number(g_mapSamReg[strSampleCode]).toLatin1().data());

	QString strErrMsg = "";
	QDStrs dsFields;
	if (false == g_pLocalDbThread->AddDbOperTask(&sDbOpeContent, &dsFields, strErrMsg))
	{
		ADDMSG("数据库模块", enEventAlarm, FL, _Q(strErrMsg));
		return;
	}
}

void CSamReg::RegistrationOK()
{
	g_nChangedFlag = 1;//防止重复计算重量
	if (ui.SampleCodeLineEdit->text() == "")
	{
		QMessageBox::critical(NULL, "error", "采样编码编辑框无内容", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
		return;
	}
	QString strSampleCode = ui.SampleCodeLineEdit->text();
	int nVenNo = 0;
	QString strSampleCodeInsertTime;
	//在oracle数据库中查找有没有此采样码
	DbOperContent sDbOpeContent(enumSqlType::enenThreeLevelCode);
	if (NULL == sDbOpeContent.pThreeLevelCodeTable)
	{
		ADDMSG("数据库模块", enEventAlarm, FL, _Q(QString("三级编码表指针创建失败")));
		return;
	}
	sDbOpeContent.pThreeLevelCodeTable->nOpType = 0; //根据采样码查出制样码
	strcpy(sDbOpeContent.pThreeLevelCodeTable->szSampleCode, strSampleCode.toLatin1().data());
	QString strErrMsg = "";
	QDStrs dsFields;
	if (g_nOracleorAccess == 0)
	{
		if (false == g_pDbThread->AddDbOperTask(&sDbOpeContent, &dsFields, strErrMsg))
		{
			ADDMSG("数据库模块", enEventAlarm, FL, _Q(strErrMsg));
			return ;
		}
	}
	else
	{
		if (false == g_pLocalDbThread->AddDbOperTask(&sDbOpeContent, &dsFields, strErrMsg))
		{
			ADDMSG("数据库模块", enEventAlarm, FL, _Q(strErrMsg));
			return ;
		}
	}
	if (dsFields.size() == 0)  //表明没有查找到数据,说明数据库三级编码表中没有这个采样码对应的样品记录
	{
		QMessageBox::critical(NULL, "error", "此采样码不存在,请重新输入", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
		return;
	}
	else
	{
		//拿到供应商编号
		for (int i = 0; i < dsFields.size(); i++)
		{
			QVector<QString> vecThreeLeavelCode = dsFields.at(i);
			nVenNo = vecThreeLeavelCode.at(0).toFloat();
			strSampleCodeInsertTime = vecThreeLeavelCode.at(14);
		}
	}

	//在本地数据库制样登记表中查询此采样码的记录之间是否提交过,如果已经提交过,直接返回
	{
		DbOperContent sDbOpeContent(enumSqlType::enSamReg);
		if (NULL == sDbOpeContent.pSampleRegTable)
		{
			ADDMSG("数据库模块", enEventAlarm, FL, _Q(QString("样品登记表指针创建失败")));
			return;
		}
		sDbOpeContent.pSampleRegTable->nOpType = 7;
		strcpy(sDbOpeContent.pSampleRegTable->strSampleCode, strSampleCode.toLatin1().data());
		QString strErrMsg = "";
		QDStrs dsFields;
		if (false == g_pLocalDbThread->AddDbOperTask(&sDbOpeContent, &dsFields, strErrMsg))
		{
			ADDMSG("数据库模块", enEventAlarm, FL, _Q(strErrMsg));
			return;
		}
		for (int i = 0; i < dsFields.size(); i++)
		{
			QVector<QString> vecSampleRegTable = dsFields.at(i);
			if (vecSampleRegTable.size() < 5)
			{
				ADDMSG("数据库模块", enEventAlarm, FL, _Q(QString("样品登记表中的列数过少，第%d行数据无效")));
			}
			QString strIsSubmit = vecSampleRegTable.at(5);
			if (strIsSubmit == "1")
			{
				QMessageBox::critical(NULL, "error", "此采样码对应的样品已经合样提交,请勿重复登记", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
				return;
			}
		}
	}

	//是否打开合样归批
	if (g_nIsOpenStandCar == 1)
	{
		float fCarNumCount = 0;//车数
		//判断是否需要合样归批
		//2.计算供应商对应采样码下的车数
		{
			DbOperContent sDbOpeContent(enumSqlType::enenThreeLevelCode);
			if (NULL == sDbOpeContent.pThreeLevelCodeTable)
			{
				ADDMSG("数据库模块", enEventAlarm, FL, _Q(QString("三级编码表指针创建失败")));
				return;
			}
			sDbOpeContent.pThreeLevelCodeTable->nOpType = 4; //在采样记录表中查询到对应采样码所对应的车数
			strcpy(sDbOpeContent.pThreeLevelCodeTable->szSampleCode, strSampleCode.toLatin1().data());
			QString strErrMsg = "";
			QDStrs dsFields;
			if (g_nOracleorAccess == 0)
			{
				if (false == g_pDbThread->AddDbOperTask(&sDbOpeContent, &dsFields, strErrMsg))
				{
					ADDMSG("数据库模块", enEventAlarm, FL, _Q(strErrMsg));
					return ;
				}
			}
			else
			{
				if (false == g_pLocalDbThread->AddDbOperTask(&sDbOpeContent, &dsFields, strErrMsg))
				{
					ADDMSG("数据库模块", enEventAlarm, FL, _Q(strErrMsg));
					return ;
				}

			}
			if (dsFields.size() > 0) 
			{
				for (int i = 0; i < dsFields.size(); i++)
				{
					QVector<QString> vecThreeLeavelCode = dsFields.at(i);
					fCarNumCount = vecThreeLeavelCode.at(0).toFloat();
				}
			}
		}
		//3.车数与设定的标准进行比较(ini设定一般5车)
		if (fCarNumCount < g_fStandWeight)//如果小于合样归批设置的5车,可以继续合阳归批
		{
			QString strPreSampleCode = "";

			//6.判断当前供应商当天是否占用多套三级编码
			DbOperContent sDbOpeContent(enumSqlType::enenThreeLevelCode);
			if (NULL == sDbOpeContent.pThreeLevelCodeTable)
			{
				ADDMSG("数据库模块", enEventAlarm, FL, _Q(QString("三级编码表指针创建失败")));
				return;
			}
			sDbOpeContent.pThreeLevelCodeTable->nOpType = 5; //
			strcpy(sDbOpeContent.pThreeLevelCodeTable->szProviderNo, QString::number(nVenNo).toLatin1().data());
			QString strErrMsg = "";
			QDStrs dsFields;
			if (g_nOracleorAccess == 0)
			{
				if (false == g_pDbThread->AddDbOperTask(&sDbOpeContent, &dsFields, strErrMsg))
				{
					ADDMSG("数据库模块", enEventAlarm, FL, _Q(strErrMsg));
					return;
				}
			}
			else
			{
				if (false == g_pLocalDbThread->AddDbOperTask(&sDbOpeContent, &dsFields, strErrMsg))
				{
					ADDMSG("数据库模块", enEventAlarm, FL, _Q(strErrMsg));
					return;
				}

			}
			if (dsFields.size() > 1)  //表明占用了多套编码
			{
				//拿到上一套采样编码
				QVector<QString> vecThreeLeavelCode = dsFields.at(0);
				strPreSampleCode = vecThreeLeavelCode.at(3);
				int nret = QMessageBox::information(NULL, "", QString("此采样码对应的样品可以合样归批到采样码为%1的样品中,是否执行").arg(strPreSampleCode), QMessageBox::Yes, QMessageBox::No);
				if (nret == QMessageBox::Yes)
				{
					strSampleCode = strPreSampleCode;
				}
			}
			else if (dsFields.size() == 1)
			{
				//不能合样归批
			}
		}
	}

	QString strCurrentDateTime = QDateTime::currentDateTime().toString("yyyy/MM/dd hh:mm:ss");
	SamRegItem* pSamRegItem = new SamRegItem();
	pSamRegItem->isChecked = false;
	pSamRegItem->isSubmitOK = false;
	strcpy(pSamRegItem->strSampleCode, strSampleCode.toLatin1().data());
	strcpy(pSamRegItem->strInsertTime, strCurrentDateTime.toLatin1().data());
	g_vecSamRegItem.push_back(pSamRegItem);
	int nRowCount = m_pSamRegistrationModel->rowCount();
	QList<QStandardItem*> item;
	item.append(new QStandardItem());//选择
	item.append(new QStandardItem(strSampleCode));//采样编码
	item.append(new QStandardItem(ui.lineEditWeight->text()));//重量
	item.append(new QStandardItem(strCurrentDateTime));//插入记录的时间
	item.append(new QStandardItem(""));//备注
	//设置居中显示
	for (int nRow = 0; nRow < item.count(); nRow++)
	{
		item.at(nRow)->setTextAlignment(Qt::AlignCenter);
	}
	m_pSamRegistrationModel->insertRow(m_pSamRegistrationModel->rowCount(), item);
	//添加复选框
	QWidget *pwidget = new QWidget;
	QHBoxLayout *hlayout = new QHBoxLayout;
	hlayout->setAlignment(Qt::AlignLeft);
	QCheckBox *chebox = new QCheckBox;
	chebox->setObjectName("singleCheck");
	hlayout->addWidget(chebox);
	pwidget->setLayout(hlayout);
	connect(chebox, SIGNAL(clicked()), this, SLOT(slot_tCheckItem()));
	ui.widget->ui.tableView->setIndexWidget(m_pSamRegistrationModel->index(nRowCount, 0), pwidget);

	//在本地的Access数据库中插入一条样品登记记录
	int nFlag = 0;
	InsertAccessSamReg(strCurrentDateTime, strSampleCode, ui.lineEditWeight->text(), nFlag);
	strcpy(g_vecSamRegItem[nRowCount]->strSampleWeight, ui.lineEditWeight->text().toLatin1().data());
	if (g_nProjectNo == 3 || g_nProjectNo == 4 || g_nProjectNo == 5 || g_nProjectNo == 7)
	{
		if (nFlag == 0)
		{
			if (ui.lineEditWeight->text() == "")
			{
				QString strSampleWeight;
				{
					//首先查询到本地数据库中重量列的数值
					DbOperContent sDbOpeContent(enumSqlType::enSamReg);
					if (NULL == sDbOpeContent.pSampleRegTable)
					{
						ADDMSG("数据库模块", enEventAlarm, FL, _Q(QString("样品登记表指针创建失败")));
						return;
					}
					sDbOpeContent.pSampleRegTable->nOpType = 7;
					strcpy(sDbOpeContent.pSampleRegTable->strSampleCode, strSampleCode.toLatin1().data());
					QString strErrMsg = "";
					QDStrs dsFields;
					if (false == g_pLocalDbThread->AddDbOperTask(&sDbOpeContent, &dsFields, strErrMsg))
					{
						ADDMSG("数据库模块", enEventAlarm, FL, _Q(strErrMsg));
						return;
					}
					for (int i = 0; i < dsFields.size(); i++)
					{
						QVector<QString> vecSampleRegTable = dsFields.at(i);
						if (vecSampleRegTable.size() < 5)
						{
							ADDMSG("数据库模块", enEventAlarm, FL, _Q(QString("样品登记表中的列数过少，第%d行数据无效")));
						}
						strSampleWeight = vecSampleRegTable.at(2);
					}
				}
				QString strNewWeight = QString::number(strSampleWeight.toFloat() + ui.lineEditWeight->text().toFloat());
				//将修改后的重量同步记录到本地数据库中
				DbOperContent sDbOpeContent(enumSqlType::enSamReg);
				if (NULL == sDbOpeContent.pSampleRegTable)
				{
					ADDMSG("数据库模块", enEventAlarm, FL, _Q(QString("样品登记表指针创建失败")));
					return;
				}
				sDbOpeContent.pSampleRegTable->nOpType = 2; //更新本地数据库重量信息
				strcpy(sDbOpeContent.pSampleRegTable->strSampleWeight, strNewWeight.toLatin1().data());
				strcpy(sDbOpeContent.pSampleRegTable->strSampleCode, strSampleCode.toLatin1().data());
				QString strErrMsg = "";
				QDStrs dsFields;
				if (false == g_pLocalDbThread->AddDbOperTask(&sDbOpeContent, &dsFields, strErrMsg))
				{
					ADDMSG("数据库模块", enEventAlarm, FL, _Q(strErrMsg));
					return;
				}
			}
		}
	}

	ui.SampleCodeLineEdit->clear();
	//QMessageBox::information(NULL, "", QString("登记成功"), QMessageBox::Yes, QMessageBox::No);
	QString sAddMsg = A2T("确认登记");
	ADDMSG("系统信息", enEventAlarm, FL, _Q(sAddMsg));

	//最后打印临时码（采样码）
	if (g_nProjectNo == 3 || g_nProjectNo == 4)
	{
		if (NULL == m_pParent->m_lpPrintLabel)
		{
			QMessageBox::critical(NULL, "error", "失败,驱动函数未加载成功", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
			return;
		}
		QString strTime = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
		//执行打印函数
		QString str6MMSize = strSampleCode;
		m_pParent->m_lpPrintLabel(str6MMSize.toLocal8Bit().data(), strSampleCode.toLatin1().data(), strTime.toLatin1().data());
	}
	ui.SampleCodeLineEdit->clear();
	if (g_nProjectNo != 5)//西来峰项目样品重量在最后补录
	{
		if (ui.radioButton->isChecked())//选中则不可编辑
			return;
		else
			ui.lineEditWeight->clear();
		
	}

	if (g_nProjectNo == 6)//河津默认重量0
	{
		ui.lineEditWeight->setText("0");
	}
	if (g_nProjectNo == 7)//7:新疆天河 默认重量0并且隐藏
	{
		ui.lineEditWeight->setText("0");
		ui.labelWeight->hide();
		ui.lineEditWeight->hide();
	}


	// 将焦点设置到 QLineEdit 上,用于继续扫码
	ui.SampleCodeLineEdit->setFocus();
}

//合阳提交
void CSamReg::SamSubmission()
{
	//判断是否没有勾选完全
	int n = g_vecSamRegItem.size();
	for (QVector<SamRegItem*>::iterator it = g_vecSamRegItem.begin(); it != g_vecSamRegItem.end(); it++)
	{
		SamRegItem* item = *it;
		if (item->isChecked == false)//遇到没有勾选的记录不做判断
		{
			n--;
			continue;
		}
		for (QVector<SamRegItem*>::iterator itor = g_vecSamRegItem.begin(); itor != g_vecSamRegItem.end(); itor++)
		{
			SamRegItem* temp = *itor;
			if (strcmp(temp->strSampleCode, item->strSampleCode) == 0)
			{
				if (temp->isChecked == false)
				{
					QMessageBox::information(NULL, "", QString("采样码为%1的样品记录没有勾选完全,请全部勾选后提交").arg(temp->strSampleCode), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
					return;
				}
			}
		}
	}

	if (0 == n)
	{
		QMessageBox::information(NULL, "", QString("请勾选需要提交的记录后再点击合样提交"), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
		return;
	}

	//判断勾选的数据中是否有重量没有填写完成
	for (QVector<SamRegItem*>::iterator it = g_vecSamRegItem.begin(); it != g_vecSamRegItem.end(); it++)
	{
		SamRegItem* item = *it;
		if (item->isChecked == true)
		{
			if (strcmp(item->strSampleWeight, "") == 0)
			{
				QMessageBox::information(NULL, "", "勾选的记录中重量信息未填写完全,请填写完整", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
				return;
			}
		}
	}

	//1.将被选择的样品的重量相加得到总重量
	g_mapSamReg.clear();//提交之前将全局Map清空
	for (QVector<SamRegItem*>::iterator it = g_vecSamRegItem.begin(); it != g_vecSamRegItem.end(); it++)
	{
		SamRegItem* item = *it;
		if (item->isChecked == true)
		{
			//判断此采样编码在g_mapSamReg中是否存在
			if (g_mapSamReg.find(QString(item->strSampleCode)) != g_mapSamReg.end())//存在,则在原来的基础上重量值进行累加
			{
				g_mapSamReg[QString(item->strSampleCode)] += atof(item->strSampleWeight);
			}
			else  //不存在,则需要在g_mapSamReg中追加
			{
				g_mapSamReg.insert(QString(item->strSampleCode), atof(item->strSampleWeight));
			}
		}
	}
	//2.根据采样码关联出制样码
	bool btemp = false;
	int nTime = 0;
	for (QMap<QString, float>::Iterator it = g_mapSamReg.begin(); it != g_mapSamReg.end(); it++)
	{
		btemp = QueryThreeLevelCodeTable(it.key(), nTime);
		if (true == btemp)
		{
			int i = 0;
			//将全局数组中的提交成功的标志置为1
			for (QVector<SamRegItem*>::iterator itor = g_vecSamRegItem.begin(); itor != g_vecSamRegItem.end(); itor++)
			{
				SamRegItem* item = *itor;
				if (0 == strcmp(item->strSampleCode, it.key().toLatin1().data()))
				{
					item->isSubmitOK = true;
				}
			}
			if (g_nProjectNo == 7)//7:新疆天河
			{
				ADDMSG("系统信息", enEventInfo, FL, _Q(QString("采样码为%1的样品记录合样提交成功").arg(it.key())));
				QMessageBox::information(NULL, "", QString("采样码为%1的样品记录合样提交成功").arg(it.key()), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
			}
			else
			{
				ADDMSG("系统信息", enEventInfo, FL, _Q(QString("采样码为%1的样品记录合样提交成功,样品质量为%2KG").arg(it.key()).arg(it.value())));
				QMessageBox::information(NULL, "", QString("采样码为%1的样品记录合样提交成功,样品质量为%2KG").arg(it.key()).arg(it.value()), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
			}
			
		}
		else
		{
			QMessageBox::information(NULL, "", QString("采样码为%1的样品记录合样提交失败").arg(it.key()), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
			return;
		}
		nTime++;
	}
	//3.将本地制样登记表中对应记录设置为已经提交
	for (QVector<SamRegItem*>::iterator it = g_vecSamRegItem.begin(); it != g_vecSamRegItem.end(); it++)
	{
		SamRegItem* item = *it;
		if (item->isChecked == true)
		{
			DbOperContent sDbOpeContent(enumSqlType::enSamReg);
			if (NULL == sDbOpeContent.pSampleRegTable)
			{
				ADDMSG("数据库模块", enEventAlarm, FL, _Q(QString("样品登记表指针创建失败")));
				return;
			}
			sDbOpeContent.pSampleRegTable->nOpType = 8;
			strcpy(sDbOpeContent.pSampleRegTable->strSampleCode, item->strSampleCode);
			QString strErrMsg = "";
			QDStrs dsFields;
			if (false == g_pLocalDbThread->AddDbOperTask(&sDbOpeContent, &dsFields, strErrMsg))
			{
				ADDMSG("数据库模块", enEventAlarm, FL, _Q(strErrMsg));
				return;
			}
		}
	}
	//4.提交完毕将打钩的记录在TableView和全局数组中删掉
	int i = 0;
	for (QVector<SamRegItem*>::iterator it = g_vecSamRegItem.begin(); it != g_vecSamRegItem.end(); it++)
	{
		SamRegItem* item = *it;
		if (item->isSubmitOK == true)
		{
			m_pSamRegistrationModel->removeRow(i);//删除tableview中选中的行
			if (nullptr != *it)
			{
				SAFE_DELETE(g_vecSamRegItem[i]);
			}
			g_vecSamRegItem.erase(it);
			it--;//迭代器回退
			i--;
		}
		i++;
	}
	//最后将全选复选框设为未选中
	ui.checkBox->setCheckState(Qt::Unchecked);
	return;
}

void CSamReg::RecordDelete()
{
	int nCount = 0;
	int i = 0;
	for (QVector<SamRegItem*>::iterator it = g_vecSamRegItem.begin(); it != g_vecSamRegItem.end(); it++)
	{
		SamRegItem* item = *it;
		if (item->isChecked == true)//选中了
		{
			nCount++;
		}
	}
	if (nCount == 0)
	{
		QMessageBox::information(NULL, "", QString("勾选的记录条数为0,请勾选之后再进行删除"), QMessageBox::Yes, QMessageBox::No);
		return;
	}
	int ret = QMessageBox::information(NULL, "", QString("是否确认删除"), QMessageBox::Yes, QMessageBox::No);
	if (ret == QMessageBox::No)
	{
		return;
	}
	QString strNewWeight;
	QString strOldWeight;
	for (QVector<SamRegItem*>::iterator it = g_vecSamRegItem.begin(); it != g_vecSamRegItem.end(); it++)
	{
		SamRegItem* item = *it;
		if (item->isChecked == true)//选中了
		{
			//首先得到此采样编码对应的记录中的重量信息
			DbOperContent sDbOpeContent(enumSqlType::enSamReg);
			if (NULL == sDbOpeContent.pSampleRegTable)
			{
				ADDMSG("数据库模块", enEventAlarm, FL, _Q(QString("样品登记表指针创建失败")));
				return;
			}
			sDbOpeContent.pSampleRegTable->nOpType = 7;
			strcpy(sDbOpeContent.pSampleRegTable->strSampleCode, item->strSampleCode);
			QString strErrMsg = "";
			QDStrs dsFields;
			if (false == g_pLocalDbThread->AddDbOperTask(&sDbOpeContent, &dsFields, strErrMsg))
			{
				ADDMSG("数据库模块", enEventAlarm, FL, _Q(strErrMsg));
				return;
			}
			for (int n = 0; n < dsFields.size(); n++)
			{
				QVector<QString> vecSampleRegTable = dsFields.at(n);
				if (vecSampleRegTable.size() < 5)
				{
					ADDMSG("数据库模块", enEventAlarm, FL, _Q(QString("样品登记表中的列数过少，第%d行数据无效")));
				}
				strOldWeight = vecSampleRegTable.at(2);
				strNewWeight = QString::number(strOldWeight.toFloat() - QString(item->strSampleWeight).toFloat());
				if (strNewWeight.toFloat() == 0)//说明修改后记录重量为零
				{
					DbOperContent sDbOpeContent(enumSqlType::enSamReg);
					if (NULL == sDbOpeContent.pSampleRegTable)
					{
						ADDMSG("数据库模块", enEventAlarm, FL, _Q(QString("样品登记表指针创建失败")));
						return;
					}
					sDbOpeContent.pSampleRegTable->nOpType = 1; //根据插入的时间删除对应的记录
					strcpy(sDbOpeContent.pSampleRegTable->strSampleCode, item->strSampleCode);
					QString strErrMsg = "";
					QDStrs dsFields;
					if (false == g_pLocalDbThread->AddDbOperTask(&sDbOpeContent, &dsFields, strErrMsg))
					{
						ADDMSG("数据库模块", enEventAlarm, FL, _Q(strErrMsg));
						return;
					}
				}
				else
				{
					//将修改后的重量同步记录到本地数据库中
					DbOperContent sDbOpeContent(enumSqlType::enSamReg);
					if (NULL == sDbOpeContent.pSampleRegTable)
					{
						ADDMSG("数据库模块", enEventAlarm, FL, _Q(QString("样品登记表指针创建失败")));
						return;
					}
					sDbOpeContent.pSampleRegTable->nOpType = 2; //更新本地数据库重量信息
					strcpy(sDbOpeContent.pSampleRegTable->strSampleWeight, strNewWeight.toLatin1().data());
					strcpy(sDbOpeContent.pSampleRegTable->strSampleCode, item->strSampleCode);
					QString strErrMsg = "";
					QDStrs dsFields;
					if (false == g_pLocalDbThread->AddDbOperTask(&sDbOpeContent, &dsFields, strErrMsg))
					{
						ADDMSG("数据库模块", enEventAlarm, FL, _Q(strErrMsg));
						return;
					}
				}
			}
			m_pSamRegistrationModel->removeRow(i);//删除tableview中选中的行
			if (nullptr != *it)
			{
				SAFE_DELETE(g_vecSamRegItem[i]);
			}
			g_vecSamRegItem.erase(it);
			it--;//迭代器回退
			i--;
		}
		i++;
	}
	QMessageBox::information(NULL, "", QString("记录删除成功,删除了%1条记录").arg(nCount), QMessageBox::Yes, QMessageBox::No);
	return;
}

void CSamReg::on_CurrentChanged(const QModelIndex &current, const QModelIndex &previous, const QVector<int> &roles)
{
	//选择的单元格发生变化
	if (current.isValid())
	{
		if (g_nChangedFlag == 1)
		{
			if (current.column() == 2)//如果改变的是第2列,说明是重量编辑框进行了状态的改变
			{
				QModelIndex SampleCodeIndex = m_pSamRegistrationModel->index(current.row(), 1);
				QString strSampleCode = m_pSamRegistrationModel->data(SampleCodeIndex).toString();
				QModelIndex WeightIndex = m_pSamRegistrationModel->index(current.row(), 2);
				QString strWeight = m_pSamRegistrationModel->data(WeightIndex).toString();
				QModelIndex InsertTimeIndex = m_pSamRegistrationModel->index(current.row(), 3);
				QString strInsertTime = m_pSamRegistrationModel->data(InsertTimeIndex).toString();
				//将全局的数据中对应的重量信息做出相应的变化
				int n = current.row();
				strcpy(g_vecSamRegItem[current.row()]->strSampleWeight, strWeight.toLatin1().data());
				QStandardItem* aItem = m_pSamRegistrationModel->itemFromIndex(current);
				//得到此行的重量和插入时间\采样码

				QString strSampleWeight;
				{
					//首先查询到本地数据库中重量列的数值
					DbOperContent sDbOpeContent(enumSqlType::enSamReg);
					if (NULL == sDbOpeContent.pSampleRegTable)
					{
						ADDMSG("数据库模块", enEventAlarm, FL, _Q(QString("样品登记表指针创建失败")));
						return;
					}
					sDbOpeContent.pSampleRegTable->nOpType = 7;
					strcpy(sDbOpeContent.pSampleRegTable->strSampleCode, strSampleCode.toLatin1().data());
					QString strErrMsg = "";
					QDStrs dsFields;
					if (false == g_pLocalDbThread->AddDbOperTask(&sDbOpeContent, &dsFields, strErrMsg))
					{
						ADDMSG("数据库模块", enEventAlarm, FL, _Q(strErrMsg));
						return;
					}
					for (int i = 0; i < dsFields.size(); i++)
					{
						QVector<QString> vecSampleRegTable = dsFields.at(i);
						if (vecSampleRegTable.size() < 5)
						{
							ADDMSG("数据库模块", enEventAlarm, FL, _Q(QString("样品登记表中的列数过少，第%d行数据无效")));
						}
						strSampleWeight = vecSampleRegTable.at(2);
					}
				}
				QString strNewWeight = QString::number(strSampleWeight.toFloat() + strWeight.toFloat());
				//将修改后的重量同步记录到本地数据库中
				DbOperContent sDbOpeContent(enumSqlType::enSamReg);
				if (NULL == sDbOpeContent.pSampleRegTable)
				{
					ADDMSG("数据库模块", enEventAlarm, FL, _Q(QString("样品登记表指针创建失败")));
					return;
				}
				sDbOpeContent.pSampleRegTable->nOpType = 2; //更新本地数据库重量信息
				strcpy(sDbOpeContent.pSampleRegTable->strSampleWeight, strNewWeight.toLatin1().data());
				strcpy(sDbOpeContent.pSampleRegTable->strSampleCode, strSampleCode.toLatin1().data());
				QString strErrMsg = "";
				QDStrs dsFields;
				if (false == g_pLocalDbThread->AddDbOperTask(&sDbOpeContent, &dsFields, strErrMsg))
				{
					ADDMSG("数据库模块", enEventAlarm, FL, _Q(strErrMsg));
					return;
				}
			}
			if (current.column() == 4)//如果改变的是第4列,说明是备注编辑框进行了状态的改变
			{
				QStandardItem* aItem = m_pSamRegistrationModel->itemFromIndex(current);
				//得到此行的重量和插入时间
				QModelIndex SampleCodeIndex = m_pSamRegistrationModel->index(current.row(), 1);
				QString strSampleCode = m_pSamRegistrationModel->data(SampleCodeIndex).toString();
				QModelIndex RemarkIndex = m_pSamRegistrationModel->index(current.row(), 4);
				QString strRemark = m_pSamRegistrationModel->data(RemarkIndex).toString();
				QModelIndex InsertTimeIndex = m_pSamRegistrationModel->index(current.row(), 3);
				QString strInsertTime = m_pSamRegistrationModel->data(InsertTimeIndex).toString();
				//将全局的数据中对应的备注信息做出相应的变化
				int n = current.row();
				strcpy(g_vecSamRegItem[current.row()]->strRemarks, strRemark.toLocal8Bit());
				//将修改后的重量同步记录到本地数据库中
				DbOperContent sDbOpeContent(enumSqlType::enSamReg);
				if (NULL == sDbOpeContent.pSampleRegTable)
				{
					ADDMSG("数据库模块", enEventAlarm, FL, _Q(QString("样品登记表指针创建失败")));
					return;
				}
				sDbOpeContent.pSampleRegTable->nOpType = 6; //更新本地数据库备注信息
				strcpy(sDbOpeContent.pSampleRegTable->strRemarks, strRemark.toLocal8Bit());
				strcpy(sDbOpeContent.pSampleRegTable->strSampleCode, strSampleCode.toLatin1().data());
				QString strErrMsg = "";
				QDStrs dsFields;
				if (false == g_pLocalDbThread->AddDbOperTask(&sDbOpeContent, &dsFields, strErrMsg))
				{
					ADDMSG("数据库模块", enEventAlarm, FL, _Q(strErrMsg));
					return;
				}
			}
		}
	}
}

void CSamReg::slot_checkAll(int status)
{
	int count = m_pSamRegistrationModel->rowCount();
	if (status == 2)
	{
		for (int i = 0; i < g_vecSamRegItem.size(); i++)
		{
			g_vecSamRegItem[i]->isChecked = true;
		}
	}
	else if (status == 0)
	{
		for (int i = 0; i < g_vecSamRegItem.size(); i++)
		{
			g_vecSamRegItem[i]->isChecked = false;
		}
	}
	for (int i = 0; i < count; i++)
	{
		QWidget *widget = ui.widget->ui.tableView->indexWidget(m_pSamRegistrationModel->index(i, 0));
		QCheckBox *check = widget->findChild<QCheckBox *>("singleCheck");
		switch (status) {
		case 0:
			check->setCheckState(Qt::CheckState::Unchecked);
			break;
		case 1:
			//check->setCheckState(Qt::CheckState::PartiallyChecked);
			break;
		case 2:
			check->setCheckState(Qt::CheckState::Checked);
			break;
		}
	}
}

void CSamReg::slot_tCheckItem()
{
	int count = m_pSamRegistrationModel->rowCount();   //总行数
	QMap<int, int> rowMap;    //选中状态的map
	for (int i = 0; i < count; i++) {
		QWidget *widget = ui.widget->ui.tableView->indexWidget(m_pSamRegistrationModel->index(i, 0));
		QCheckBox *check = widget->findChild<QCheckBox *>("singleCheck");
		int status = check->checkState();    //按钮的状态
		switch (status) {
		case 0:
			rowMap.insert(i, 0);
			g_vecSamRegItem[i]->isChecked = false;
			break;
		case 1:
			break;
		case 2:
			rowMap.insert(i, 1);    //如果是选中状态移除
			g_vecSamRegItem[i]->isChecked = true;
			break;
		}
	}

	int tcount = 0;   //打沟的数量
	int fcount = 0;   //不打沟的数量
	QMapIterator<int, int> rowMapIterator(rowMap);
	rowMapIterator.toBack();
	while (rowMapIterator.hasPrevious())
	{
		int value;
		rowMapIterator.previous();
		value = rowMapIterator.value();
		if (value == 0) {
			fcount++;
		}
		else if (value == 1) {
			tcount++;
		}
	}

	//根据数量判断  全选状态
	if (tcount == count) {
		ui.checkBox->setCheckState(Qt::CheckState::Checked);
	}
	else if (fcount == count) {
		ui.checkBox->setCheckState(Qt::CheckState::Unchecked);
	}
	else {
		ui.checkBox->setCheckState(Qt::CheckState::PartiallyChecked);
	}
}

void CSamReg::slot_ReadSampleCode()
{
	if (g_nProjectNo == 2 || g_nProjectNo == 4 || g_nProjectNo == 6)
	{
		if (NULL == m_pParent->m_lpStartCodeDevice || NULL == m_pParent->m_lpStopCodeDevice || NULL == m_pParent->m_lpWriteCode || NULL == m_pParent->m_lpReadCode)
		{
			QMessageBox::critical(NULL, "error", "失败,驱动函数未加载", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
			return;
		}
		//先开启设备
		const char* szDeviceId = "";
		const char* szConfig = "";
		int ret = m_pParent->m_lpStartCodeDevice(szDeviceId, szConfig);
		if (ret == 0)
		{
			wchar_t strCode[33];
			//从配置文件中拿到读取的块号
			QSettings configIniRead(g_strConfigPath, QSettings::IniFormat);
			int nDataBlockNo = configIniRead.value("MAIN/nDataBlockNo", "8").toInt();
			//读取芯片中的采样编码
			ret = m_pParent->m_lpReadCode(nDataBlockNo, strCode);
			if (ret == 0)
			{
				QString strTemp;
				Hex16ToQString(strCode, 32, strTemp);
				ADDMSG("数据库模块", enEventAlarm, FL, _Q(QString("读到了字符串：%1").arg(strTemp)));
				ui.SampleCodeLineEdit->setText(strTemp.left(11));
				//读取成功关闭读写器
				ret = m_pParent->m_lpStopCodeDevice(NULL);
				if (0 != ret)
				{
					QMessageBox::critical(NULL, "error", "关闭写码器失败1", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
					return;
				}
			}
			else
			{
				QMessageBox::critical(NULL, "error", "读取采样码失败", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
				return;
			}
		}
		else
		{
			QMessageBox::critical(NULL, "error", "连接读码器失败", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
			return;
		}
	}
	else if (g_nProjectNo == 3)//岱海使用的是D9151
	{
		QString sStr = "";
		QString sStr5 = "";

		char *chData = new char();
		char *szReMsg = new char();
		m_pParent->m_RfidReadData(6, "", chData, szReMsg);
	}

}

void CSamReg::slot_GetWeightCode()
{
	//必须选中一行才能继续操作
	int nRow = ui.widget->ui.tableView->currentIndex().row();
	if (nRow < 0)
	{
		QMessageBox::information(NULL, "", ("请选择一条记录后再进行操作"));
		return;
	}

	if (m_pParent->m_bIsOpenWeight == false)
	{
		if (1)
		{
			char szRunDesc[1024] = { 0 };
			bool bRet = m_pParent->m_lpStartAllWeightBridge(CManualSampleSys::RecvCallBack, szRunDesc);
			if (bRet == true)
			{
				m_pParent->m_bIsOpenWeight = true;
			}
			else
			{
				m_pParent->m_bIsOpenWeight = false;
			}
		}
	}
	char szRunDesc[1024] = { 0 };
	float fWeight = 0.0;
	bool ret = m_pParent->m_lpGetNowWeight("160001", szRunDesc);
	if (ret == false)
	{
		QMessageBox::critical(NULL, "error", "读取重量失败", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
		return;
	}
}

void CSamReg::slot_PrintSampleCode()
{
	if (ui.SampleCodeLineEdit->text() == "")
	{
		QMessageBox::critical(NULL, "error", "请先手动输入采样编码后再进行打印", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
		return;
	}
	if (NULL == m_pParent->m_lpPrintLabel)
	{
		QMessageBox::critical(NULL, "error", "失败,驱动函数未加载成功", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
		return;
	}
	QString strTime = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
	//执行打印函数
	QString str6MMSize = ui.SampleCodeLineEdit->text();
	m_pParent->m_lpPrintLabel(str6MMSize.toLocal8Bit().data(), ui.SampleCodeLineEdit->text().toLatin1().data(), strTime.toLatin1().data());
}

void CSamReg::on_AddAccessToTableView()
{
	//不能重复进行更新到列表的操作
	g_nChangedFlag = 0;//防止重复计算重量
	//将本地未提交的记录更新到列表中
	DbOperContent sDbOpeContent(enumSqlType::enSamReg);
	if (NULL == sDbOpeContent.pSampleRegTable)
	{
		ADDMSG("数据库模块", enEventAlarm, FL, _Q(QString("样品登记表指针创建失败")));
		return;
	}
	sDbOpeContent.pSampleRegTable->nOpType = 9; //查询没有提交的数据
	QString strErrMsg = "";
	QDStrs dsFields;
	if (false == g_pLocalDbThread->AddDbOperTask(&sDbOpeContent, &dsFields, strErrMsg))
	{
		ADDMSG("数据库模块", enEventAlarm, FL, _Q(strErrMsg));
		return;
	}
	if (dsFields.size() > 0)
	{
		for (int i = 0; i < dsFields.size(); i++)
		{
			QVector<QString> vecSampleRegTable = dsFields.at(i);
			if (vecSampleRegTable.size() < 6)
			{
				ADDMSG("数据库模块", enEventAlarm, FL, _Q(QString("制样登记表中的列数过少，第%d行数据无效")));
			}
			QString strNo = vecSampleRegTable.at(0);
			QString strSampleCode = vecSampleRegTable.at(1);
			QString strSampleWeight = vecSampleRegTable.at(2);
			QString strRemarks = vecSampleRegTable.at(3);
			QString strInsertTime = vecSampleRegTable.at(4);
			QString strIsSubmit = vecSampleRegTable.at(5);

			SamRegItem* pSamRegItem = new SamRegItem();
			pSamRegItem->isChecked = false;
			pSamRegItem->isSubmitOK = false;
			strcpy(pSamRegItem->strSampleCode, strSampleCode.toLatin1().data());
			strcpy(pSamRegItem->strInsertTime, strInsertTime.toLatin1().data());
			strcpy(pSamRegItem->strSampleWeight, strSampleWeight.toLatin1().data());
			g_vecSamRegItem.push_back(pSamRegItem);
			int nRowCount = m_pSamRegistrationModel->rowCount();
			QList<QStandardItem*> item;
			item.append(new QStandardItem());//选择
			item.append(new QStandardItem(strSampleCode));//采样编码
			item.append(new QStandardItem(strSampleWeight));//重量
			item.append(new QStandardItem(strInsertTime));//插入记录的时间
			item.append(new QStandardItem(strRemarks));//备注
			//设置居中显示
			for (int nRow = 0; nRow < item.count(); nRow++)
			{
				item.at(nRow)->setTextAlignment(Qt::AlignCenter);
			}
			m_pSamRegistrationModel->appendRow(item);
			//添加复选框
			QWidget *pwidget = new QWidget;
			QHBoxLayout *hlayout = new QHBoxLayout;
			hlayout->setAlignment(Qt::AlignLeft);
			QCheckBox *chebox = new QCheckBox;
			chebox->setObjectName("singleCheck");
			hlayout->addWidget(chebox);
			pwidget->setLayout(hlayout);
			connect(chebox, SIGNAL(clicked()), this, SLOT(slot_tCheckItem()));
			ui.widget->ui.tableView->setIndexWidget(m_pSamRegistrationModel->index(nRowCount, 0), pwidget);

			//将更新成功的标志位设为1
			{
				DbOperContent sDbOpeContent(enumSqlType::enSamReg);
				if (NULL == sDbOpeContent.pSampleRegTable)
				{
					ADDMSG("数据库模块", enEventAlarm, FL, _Q(QString("样品登记表指针创建失败")));
					return;
				}
				sDbOpeContent.pSampleRegTable->nOpType = 10;
				sDbOpeContent.pSampleRegTable->nNo = strNo.toInt();
				QString strErrMsg = "";
				QDStrs dsFields;
				if (false == g_pLocalDbThread->AddDbOperTask(&sDbOpeContent, &dsFields, strErrMsg))
				{
					ADDMSG("数据库模块", enEventAlarm, FL, _Q(strErrMsg));
					return;
				}
			}
		}
	}
}

void CSamReg::on_RadioButton(bool flag)
{
	if (ui.radioButton->isChecked())//选中则不可编辑
		ui.lineEditWeight->setReadOnly(true);
	else
		ui.lineEditWeight->setReadOnly(false);
}
